<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>zxxhouse: src/com/zxx/view/ExpandTabView.java源文件</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">zxxhouse
   &#160;<span id="projectnumber">1.0</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- 制作者 Doxygen 1.7.6.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>首页</span></a></li>
      <li><a href="annotated.html"><span>类</span></a></li>
      <li class="current"><a href="files.html"><span>文件</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>文件列表</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">src/com/zxx/view/ExpandTabView.java</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="keyword">package </span>com.zxx.view;
<a name="l00002"></a>00002 
<a name="l00003"></a>00003 <span class="keyword">import</span> java.util.ArrayList;
<a name="l00004"></a>00004 <span class="keyword">import</span> com.soufang.ui.R;
<a name="l00005"></a>00005 <span class="keyword">import</span> android.app.Activity;
<a name="l00006"></a>00006 <span class="keyword">import</span> android.content.Context;
<a name="l00007"></a>00007 <span class="keyword">import</span> android.util.AttributeSet;
<a name="l00008"></a>00008 <span class="keyword">import</span> android.view.LayoutInflater;
<a name="l00009"></a>00009 <span class="keyword">import</span> android.view.View;
<a name="l00010"></a>00010 <span class="keyword">import</span> android.widget.LinearLayout;
<a name="l00011"></a>00011 <span class="keyword">import</span> android.widget.PopupWindow;
<a name="l00012"></a>00012 <span class="keyword">import</span> android.widget.PopupWindow.OnDismissListener;
<a name="l00013"></a>00013 <span class="keyword">import</span> android.widget.RelativeLayout;
<a name="l00014"></a>00014 <span class="keyword">import</span> android.widget.TextView;
<a name="l00015"></a>00015 <span class="keyword">import</span> android.widget.ToggleButton;
<a name="l00016"></a>00016 
<a name="l00017"></a>00017 
<a name="l00023"></a><a class="code" href="classcom_1_1zxx_1_1view_1_1_expand_tab_view.html">00023</a> <span class="keyword">public</span> <span class="keyword">class </span><a class="code" href="classcom_1_1zxx_1_1view_1_1_expand_tab_view.html" title="自定义弹出spinner控件">ExpandTabView</a> <span class="keyword">extends</span> LinearLayout implements OnDismissListener {
<a name="l00024"></a>00024 
<a name="l00025"></a>00025         <span class="keyword">private</span> ToggleButton selectedButton;
<a name="l00026"></a>00026         <span class="keyword">private</span> ArrayList&lt;RelativeLayout&gt; mViewArray = <span class="keyword">new</span> ArrayList&lt;RelativeLayout&gt;();
<a name="l00027"></a>00027         <span class="keyword">private</span> ArrayList&lt;ToggleButton&gt; mToggleButton = <span class="keyword">new</span> ArrayList&lt;ToggleButton&gt;();
<a name="l00028"></a>00028         <span class="keyword">private</span> Context mContext;
<a name="l00029"></a>00029         <span class="keyword">private</span> <span class="keyword">final</span> <span class="keywordtype">int</span> SMALL = 0;
<a name="l00030"></a>00030         <span class="keyword">private</span> <span class="keywordtype">int</span> displayWidth;
<a name="l00031"></a>00031         <span class="keyword">private</span> <span class="keywordtype">int</span> displayHeight;
<a name="l00032"></a>00032         <span class="keyword">private</span> PopupWindow popupWindow;
<a name="l00033"></a>00033         <span class="keyword">private</span> <span class="keywordtype">int</span> selectPosition;
<a name="l00034"></a>00034 
<a name="l00035"></a>00035         <span class="keyword">public</span> <a class="code" href="classcom_1_1zxx_1_1view_1_1_expand_tab_view.html" title="自定义弹出spinner控件">ExpandTabView</a>(Context context) {
<a name="l00036"></a>00036                 super(context);
<a name="l00037"></a>00037                 init(context);
<a name="l00038"></a>00038         }
<a name="l00039"></a>00039 
<a name="l00040"></a>00040         <span class="keyword">public</span> <a class="code" href="classcom_1_1zxx_1_1view_1_1_expand_tab_view.html" title="自定义弹出spinner控件">ExpandTabView</a>(Context context, AttributeSet attrs) {
<a name="l00041"></a>00041                 super(context, attrs);
<a name="l00042"></a>00042                 init(context);
<a name="l00043"></a>00043         }
<a name="l00044"></a>00044 
<a name="l00050"></a><a class="code" href="classcom_1_1zxx_1_1view_1_1_expand_tab_view.html#ac237a20e10bfaf99a7e7274eafd341bc">00050</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> <a class="code" href="classcom_1_1zxx_1_1view_1_1_expand_tab_view.html#ac237a20e10bfaf99a7e7274eafd341bc" title="设置自定义spinner的标题">setTitle</a>(String valueText, <span class="keywordtype">int</span> position) {
<a name="l00051"></a>00051                 <span class="keywordflow">if</span> (position &lt; mToggleButton.size()) {
<a name="l00052"></a>00052                         mToggleButton.get(position).setText(valueText);
<a name="l00053"></a>00053                 }
<a name="l00054"></a>00054         }
<a name="l00055"></a>00055 
<a name="l00061"></a><a class="code" href="classcom_1_1zxx_1_1view_1_1_expand_tab_view.html#ab0db2766f26a4a4071f7168c3b811d1e">00061</a>         <span class="keyword">public</span> String <a class="code" href="classcom_1_1zxx_1_1view_1_1_expand_tab_view.html#ab0db2766f26a4a4071f7168c3b811d1e" title="获取自定义spinner标题">getTitle</a>(<span class="keywordtype">int</span> position) {
<a name="l00062"></a>00062                 <span class="keywordflow">if</span> (position &lt; mToggleButton.size() &amp;&amp; mToggleButton.get(position).getText() != null) {
<a name="l00063"></a>00063                         <span class="keywordflow">return</span> mToggleButton.get(position).getText().toString();
<a name="l00064"></a>00064                 }
<a name="l00065"></a>00065                 <span class="keywordflow">return</span> <span class="stringliteral">&quot;&quot;</span>;
<a name="l00066"></a>00066         }
<a name="l00067"></a>00067 
<a name="l00072"></a><a class="code" href="classcom_1_1zxx_1_1view_1_1_expand_tab_view.html#a7d914a77eeb5be8ac5d47355e76e97c7">00072</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> <a class="code" href="classcom_1_1zxx_1_1view_1_1_expand_tab_view.html#a7d914a77eeb5be8ac5d47355e76e97c7" title="设置自定义spinner的内容">setValue</a>(<span class="comment">/*ArrayList&lt;String&gt; textArray,*/</span> ArrayList&lt;View&gt; viewArray) {
<a name="l00073"></a>00073                 <span class="keywordflow">if</span> (mContext == null) {
<a name="l00074"></a>00074                         <span class="keywordflow">return</span>;
<a name="l00075"></a>00075                 }
<a name="l00076"></a>00076                 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
<a name="l00077"></a>00077 
<a name="l00078"></a>00078                 <span class="comment">//mTextArray = textArray;</span>
<a name="l00079"></a>00079                 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; viewArray.size(); i++) {
<a name="l00080"></a>00080                         <span class="keyword">final</span> RelativeLayout r = <span class="keyword">new</span> RelativeLayout(mContext);
<a name="l00081"></a>00081                         <span class="keywordtype">int</span> maxHeight = (int) (displayHeight * 0.7);
<a name="l00082"></a>00082                         RelativeLayout.LayoutParams rl = <span class="keyword">new</span> RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, maxHeight);
<a name="l00083"></a>00083                         rl.leftMargin = 10;
<a name="l00084"></a>00084                         rl.rightMargin = 10;
<a name="l00085"></a>00085                         r.addView(viewArray.get(i), rl);
<a name="l00086"></a>00086                         mViewArray.add(r);
<a name="l00087"></a>00087                         r.setTag(SMALL);
<a name="l00088"></a>00088                         ToggleButton tButton = (ToggleButton) inflater.inflate(R.layout.toggle_button, <span class="keyword">this</span>, <span class="keyword">false</span>);
<a name="l00089"></a>00089                         addView(tButton);
<a name="l00090"></a>00090                         View line = <span class="keyword">new</span> TextView(mContext);
<a name="l00091"></a>00091                         line.setBackgroundResource(R.drawable.choosebar_line);
<a name="l00092"></a>00092                         <span class="keywordflow">if</span> (i &lt; viewArray.size() - 1) {
<a name="l00093"></a>00093                                 LinearLayout.LayoutParams lp = <span class="keyword">new</span> LinearLayout.LayoutParams(2, LinearLayout.LayoutParams.FILL_PARENT);
<a name="l00094"></a>00094                                 addView(line, lp);
<a name="l00095"></a>00095                         }
<a name="l00096"></a>00096                         mToggleButton.add(tButton);
<a name="l00097"></a>00097                         tButton.setTag(i);
<a name="l00098"></a>00098                         <span class="comment">//tButton.setText(mTextArray.get(i));</span>
<a name="l00099"></a>00099 
<a name="l00100"></a>00100                         r.setOnClickListener(<span class="keyword">new</span> OnClickListener() {
<a name="l00101"></a>00101                                 @Override
<a name="l00102"></a>00102                                 <span class="keyword">public</span> <span class="keywordtype">void</span> onClick(View v) {
<a name="l00103"></a>00103                                         <a class="code" href="classcom_1_1zxx_1_1view_1_1_expand_tab_view.html#a39b019f94740078429b7d93ba267e440" title="按返回键的处理">onPressBack</a>();
<a name="l00104"></a>00104                                 }
<a name="l00105"></a>00105                         });
<a name="l00106"></a>00106                         
<a name="l00107"></a>00107                         
<a name="l00108"></a>00108                         r.setBackgroundColor(mContext.getResources().getColor(R.color.dark_bg));
<a name="l00109"></a>00109                         tButton.setOnClickListener(<span class="keyword">new</span> OnClickListener() {
<a name="l00110"></a>00110                                 @Override
<a name="l00111"></a>00111                                 <span class="keyword">public</span> <span class="keywordtype">void</span> onClick(View view) {
<a name="l00112"></a>00112                                         <span class="comment">// initPopupWindow();</span>
<a name="l00113"></a>00113                                         ToggleButton tButton = (ToggleButton) view;
<a name="l00114"></a>00114 
<a name="l00115"></a>00115                                         <span class="keywordflow">if</span> (selectedButton != null &amp;&amp; selectedButton != tButton) {
<a name="l00116"></a>00116                                                 selectedButton.setChecked(<span class="keyword">false</span>);
<a name="l00117"></a>00117                                         }
<a name="l00118"></a>00118                                         selectedButton = tButton;
<a name="l00119"></a>00119                                         selectPosition = (Integer) selectedButton.getTag();
<a name="l00120"></a>00120                                         <a class="code" href="classcom_1_1zxx_1_1view_1_1_expand_tab_view.html#a06a8b778d444cfe095db07d6cd83460b" title="弹出菜单的设置">startAnimation</a>();
<a name="l00121"></a>00121                                         <span class="keywordflow">if</span> (mOnButtonClickListener != null &amp;&amp; tButton.isChecked()) {
<a name="l00122"></a>00122                                                 mOnButtonClickListener.onClick(selectPosition);
<a name="l00123"></a>00123                                         }
<a name="l00124"></a>00124                                 }
<a name="l00125"></a>00125                         });
<a name="l00126"></a>00126                 }
<a name="l00127"></a>00127         }
<a name="l00128"></a>00128 
<a name="l00132"></a><a class="code" href="classcom_1_1zxx_1_1view_1_1_expand_tab_view.html#a06a8b778d444cfe095db07d6cd83460b">00132</a>         <span class="keyword">private</span> <span class="keywordtype">void</span> <a class="code" href="classcom_1_1zxx_1_1view_1_1_expand_tab_view.html#a06a8b778d444cfe095db07d6cd83460b" title="弹出菜单的设置">startAnimation</a>() {
<a name="l00133"></a>00133 
<a name="l00134"></a>00134                 <span class="keywordflow">if</span> (popupWindow == null) {
<a name="l00135"></a>00135                         popupWindow = <span class="keyword">new</span> PopupWindow(mViewArray.get(selectPosition), displayWidth, displayHeight);
<a name="l00136"></a>00136                         popupWindow.setAnimationStyle(R.style.PopupWindowAnimation);
<a name="l00137"></a>00137                         popupWindow.setFocusable(<span class="keyword">false</span>);
<a name="l00138"></a>00138                         popupWindow.setOutsideTouchable(<span class="keyword">true</span>);
<a name="l00139"></a>00139                 }
<a name="l00140"></a>00140 
<a name="l00141"></a>00141                 <span class="keywordflow">if</span> (selectedButton.isChecked()) {
<a name="l00142"></a>00142                         <span class="keywordflow">if</span> (!popupWindow.isShowing()) {
<a name="l00143"></a>00143                                 <a class="code" href="classcom_1_1zxx_1_1view_1_1_expand_tab_view.html#a9d8085583ce28802f8ed7c6c2d139dbf" title="在哪个标题上显示弹出菜单">showPopup</a>(selectPosition);
<a name="l00144"></a>00144                         } <span class="keywordflow">else</span> {
<a name="l00145"></a>00145                                 popupWindow.setOnDismissListener(<span class="keyword">this</span>);
<a name="l00146"></a>00146                                 popupWindow.dismiss();
<a name="l00147"></a>00147                         }
<a name="l00148"></a>00148                 } <span class="keywordflow">else</span> {
<a name="l00149"></a>00149                         <span class="keywordflow">if</span> (popupWindow.isShowing()) {
<a name="l00150"></a>00150                                 popupWindow.dismiss();
<a name="l00151"></a>00151                         }
<a name="l00152"></a>00152                 }
<a name="l00153"></a>00153         }
<a name="l00157"></a><a class="code" href="classcom_1_1zxx_1_1view_1_1_expand_tab_view.html#a9d8085583ce28802f8ed7c6c2d139dbf">00157</a>         <span class="keyword">private</span> <span class="keywordtype">void</span> <a class="code" href="classcom_1_1zxx_1_1view_1_1_expand_tab_view.html#a9d8085583ce28802f8ed7c6c2d139dbf" title="在哪个标题上显示弹出菜单">showPopup</a>(<span class="keywordtype">int</span> position) {
<a name="l00158"></a>00158                 View tView = mViewArray.get(selectPosition).getChildAt(0);
<a name="l00159"></a>00159                 <span class="keywordflow">if</span> (tView instanceof ViewBaseAction) {
<a name="l00160"></a>00160                         ViewBaseAction f = (ViewBaseAction) tView;
<a name="l00161"></a>00161                         f.show();
<a name="l00162"></a>00162                 }
<a name="l00163"></a>00163                 <span class="keywordflow">if</span> (popupWindow.getContentView() != mViewArray.get(position)) {
<a name="l00164"></a>00164                         popupWindow.setContentView(mViewArray.get(position));
<a name="l00165"></a>00165                 }
<a name="l00166"></a>00166                 popupWindow.showAsDropDown(<span class="keyword">this</span>, 0, 0);
<a name="l00167"></a>00167         }
<a name="l00171"></a><a class="code" href="classcom_1_1zxx_1_1view_1_1_expand_tab_view.html#a39b019f94740078429b7d93ba267e440">00171</a>         <span class="keyword">public</span> <span class="keywordtype">boolean</span> <a class="code" href="classcom_1_1zxx_1_1view_1_1_expand_tab_view.html#a39b019f94740078429b7d93ba267e440" title="按返回键的处理">onPressBack</a>() {
<a name="l00172"></a>00172                 <span class="keywordflow">if</span> (popupWindow != null &amp;&amp; popupWindow.isShowing()) {
<a name="l00173"></a>00173                         popupWindow.dismiss();
<a name="l00174"></a>00174                         hideView();
<a name="l00175"></a>00175                         <span class="keywordflow">if</span> (selectedButton != null) {
<a name="l00176"></a>00176                                 selectedButton.setChecked(<span class="keyword">false</span>);
<a name="l00177"></a>00177                         }
<a name="l00178"></a>00178                         <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00179"></a>00179                 } <span class="keywordflow">else</span> {
<a name="l00180"></a>00180                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00181"></a>00181                 }
<a name="l00182"></a>00182 
<a name="l00183"></a>00183         }
<a name="l00184"></a>00184   
<a name="l00185"></a>00185         <span class="keyword">private</span> <span class="keywordtype">void</span> hideView() {
<a name="l00186"></a>00186                 View tView = mViewArray.get(selectPosition).getChildAt(0);
<a name="l00187"></a>00187                 <span class="keywordflow">if</span> (tView instanceof ViewBaseAction) {
<a name="l00188"></a>00188                         ViewBaseAction f = (ViewBaseAction) tView;
<a name="l00189"></a>00189                         f.hide();
<a name="l00190"></a>00190                 }
<a name="l00191"></a>00191         }
<a name="l00192"></a>00192 
<a name="l00193"></a>00193         <span class="keyword">private</span> <span class="keywordtype">void</span> init(Context context) {
<a name="l00194"></a>00194                 mContext = context;
<a name="l00195"></a>00195                 displayWidth = ((Activity) mContext).getWindowManager().getDefaultDisplay().getWidth();
<a name="l00196"></a>00196                 displayHeight = ((Activity) mContext).getWindowManager().getDefaultDisplay().getHeight();
<a name="l00197"></a>00197                 setOrientation(LinearLayout.HORIZONTAL);
<a name="l00198"></a>00198         }
<a name="l00199"></a>00199 
<a name="l00200"></a>00200         @Override
<a name="l00201"></a>00201         <span class="keyword">public</span> <span class="keywordtype">void</span> onDismiss() {
<a name="l00202"></a>00202                 <a class="code" href="classcom_1_1zxx_1_1view_1_1_expand_tab_view.html#a9d8085583ce28802f8ed7c6c2d139dbf" title="在哪个标题上显示弹出菜单">showPopup</a>(selectPosition);
<a name="l00203"></a>00203                 popupWindow.setOnDismissListener(null);
<a name="l00204"></a>00204         }
<a name="l00205"></a>00205 
<a name="l00206"></a>00206         <span class="keyword">private</span> OnButtonClickListener mOnButtonClickListener;
<a name="l00207"></a>00207 
<a name="l00208"></a>00208         
<a name="l00209"></a>00209         <span class="keyword">public</span> <span class="keywordtype">void</span> setOnButtonClickListener(OnButtonClickListener l) {
<a name="l00210"></a>00210                 mOnButtonClickListener = l;
<a name="l00211"></a>00211         }
<a name="l00212"></a>00212 
<a name="l00213"></a>00213         
<a name="l00214"></a>00214         <span class="keyword">public</span> <span class="keyword">interface </span>OnButtonClickListener {
<a name="l00215"></a>00215                 <span class="keyword">public</span> <span class="keywordtype">void</span> onClick(<span class="keywordtype">int</span> selectPosition);
<a name="l00216"></a>00216         }
<a name="l00217"></a>00217 
<a name="l00218"></a>00218 }
</pre></div></div><!-- contents -->


<hr class="footer"/><address class="footer"><small>
Generated at 2015年二月4日 星期三 18:11:09 for zxxhouse by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>
